import Page
from Page import Carpark
from Base.Base import Base
from selenium.webdriver.common.by import By


class CarparkIndexPage(Base):
    """
    车乐汇游戏首页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.game_home_btn = (By.XPATH, Carpark.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.game_back_btn = (By.XPATH, Carpark.RESOURCE_ID.format('ivBack'))

        # 游戏封面
        self.game_list_cover_img = (By.XPATH, Carpark.game_cover_img.format(""))

        # 游戏人数
        self.game_list_number_people_text = (By.XPATH, Carpark.game_number_people_text.format(""))

        # 游戏名称
        self.game_list_name_text = (By.XPATH, Carpark.game_name_text.format(""))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.game_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.game_back_btn)

    def get_list_cover(self, index=1):
        """
        获取游戏封面

        index 默认游戏为第一个
        :return:获取元素
        """
        self.game_list_cover_img = (By.XPATH, Carpark.game_cover_img.format(index))
        return self.find_element_o(self.game_list_cover_img)

    def get_list_number_people(self, index=1):
        """
        获取游戏人数

        index 默认游戏为第一个
        :return:获取元素
        """
        self.game_list_number_people_text = (By.XPATH, Carpark.game_number_people_text.format(index))
        return self.find_element_o(self.game_list_number_people_text)

    def get_list_name(self, index=1):
        """
        获取游戏名称

        index 默认游戏为第一个
        :return:获取元素
        """
        self.game_list_name_text = (By.XPATH, Carpark.game_name_text.format(index))
        return self.find_element_o(self.game_list_name_text)

    def is_display_carpark_index(self):
        """
        查看是否进入游戏首页

        :return:
        """
        self.game_list_name_text = (By.XPATH, Carpark.game_name_text.format(1))
        return self.is_display(self.game_list_name_text)
